import random
import matplotlib.pyplot as plt
import numpy as np
import pro
import pro.projection as projection


# 设置中文字体支持（可选）
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

# plt.ion()  # 开启交互模式
fig,ax=plt.subplots(figsize=(8,6))

ax.set_xlim(-10,100)
ax.set_ylim(-10,100)
ax.grid(True)
ax.set_aspect('equal')

# 定义起止点线段
def line(x1,y1,x2,y2):
    return [x1,y1],[x2,y2]


line_start,line_end = line(1,1,65,89)

ax.plot([line_start[0],line_end[0]],[line_start[1],line_end[1]],color='blue',linestyle='-',marker='x')

def createPoint():
    x = random.uniform(line_start[0],line_end[0])
    y = random.uniform(line_start[1],line_end[1])
    return [x,y]

for i in range(10):
    cp = createPoint()
    ax.plot(cp[0],cp[1],'ro')

    pp = projection.point_to_line_projection(cp,line_start,line_end)
    ax.plot(pp[0],pp[1],'go')



plt.show()